package com.bw.conkz;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.bean.ST1;
import com.bw.bean.ST2;
import com.bw.bean.ST3;
import com.bw.sever.SeverDao;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class Conkz {
    @Resource
    SeverDao severDao;

    @RequestMapping("/aa")
    public JSONObject show() {
        List<ST1> show = severDao.show();
        JSONObject object = new JSONObject();
        object.put("status", 0);
        object.put("msg", "");

        JSONObject object1 = new JSONObject();

        JSONArray objects = new JSONArray();
        JSONObject object2 = new JSONObject();
        object2.put("name", "考试人次");
        object2.put("id", "a");
        objects.add(object2);

        JSONObject object3 = new JSONObject();
        object3.put("name", "平均数");
        object3.put("id", "b");
        objects.add(object3);

        JSONObject object4 = new JSONObject();
        object4.put("name", "平均考试时间");
        object4.put("id", "c");
        objects.add(object4);

        object1.put("columns", objects);

        JSONArray objects1 = new JSONArray();
        for (ST1 st1 : show) {
            JSONObject object5 = new JSONObject();
            object5.put("a", st1.getA());
            object5.put("b", st1.getB());
            object5.put("c", st1.getC());
            objects1.add(object5);
        }
        object1.put("rows", objects1);


        object.put("data", object1);
        return object;
    }

    @RequestMapping("/bb")
    public JSONObject show1() {
        List<ST2> st2s = severDao.show1();
        JSONObject object = new JSONObject();
        object.put("status", 0);
        object.put("msg","");

        JSONObject object1 = new JSONObject();

        JSONArray objects = new JSONArray();
        JSONObject object2 = new JSONObject();
        object2.put("name", "学科名称");
        object2.put("id", "a");
        objects.add(object2);

        JSONObject object3 = new JSONObject();
        object3.put("name", "平均评分");
        object3.put("id", "b");
        objects.add(object3);

        JSONObject object4 = new JSONObject();
        object4.put("name", "好评人数");
        object4.put("id", "c");
        objects.add(object4);

        JSONObject object5 = new JSONObject();
        object5.put("name", "好评率");
        object5.put("id", "d");
        objects.add(object5);

        object1.put("columns", objects);

        JSONArray objects1 = new JSONArray();
        for (ST2 st2 : st2s) {
            JSONObject object6 = new JSONObject();
            object6.put("a", st2.getA());
            object6.put("b", st2.getB());
            object6.put("c", st2.getC());
            object6.put("d", st2.getD());
            objects1.add(object6);
        }
        object1.put("rows", objects1);


        object.put("data", object1);
        return object;
    }

    @RequestMapping("/cc")
    public JSONObject show2() {
        List<ST3> st3s = severDao.show2();
        JSONObject object = new JSONObject();
        object.put("status", 0);
        object.put("msg", "");

        JSONObject object1 = new JSONObject();

        for (ST3 st3 : st3s) {
            JSONArray objects = new JSONArray();
            objects.add(st3.getA());
        }
        
        object1.put("categories", object1);

        JSONArray objects1 = new JSONArray();
        for (ST3 st3 : st3s) {
            JSONObject object2 = new JSONObject();
            object2.put("b", st3.getB());

        }
        object1.put("series", objects1);
        object.put("data", object1);
        return object;
    }
    @RequestMapping("/dd")
    public JSONObject show3() {
        int i = severDao.show3();
        JSONObject object = new JSONObject();
        object.put("status",0);
        object.put("msg","");
        object.put("data",i);
        return object;
    }

}
